package cate.game.role.farm.endless;

import cate.common.table.d.GDEndless;
import cate.game.play.param.FightParam;
import cate.game.play.param.HpExtend;
import cate.game.role.Role;
import cate.game.role.RoleDependent;
import cate.game.role.farm.endless.msg.EndlessEnterResp;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.List;

@NoteClass(value = "本轮战斗们的记录")
public class EndlessCurCombats extends RoleDependent {
    @NoteField(value = "本轮战斗是否进行中")
    public boolean ing;

    @NoteField(value = "本轮需要挑战的第几关")
    public int combatNumTarget;

    @NoteField(
            value = "本轮已挑战的关卡数",
            detail =
                    "比如：今天从103关开始挑战，目前已挑战了combatCount=2场，表示103关和104关已打完，combatNumPassed=104，combatNumTarget=105")
    public int combatCount;

    @NoteField(value = "是否需要选择buff", detail = "给玩家的感觉是选择一个buff，其实本质上是选择一个对全员释放de场景技能")
    public boolean needChoose;

    @NoteField(value = "当前所选的buff选项的ID")
    public int buffOptionId = -1;

    @NoteField(value = "当前buff选项de技能ID们")
    public List<Integer> optionIds;

    @NoteField(value = "血量继承")
    public HpExtend hpExtend;

    @Override
    public void initialize(Role role) {
        super.initialize(role);
        if (combatNumTarget == 0) {
            combatNumTarget = GDEndless.COMBAT_NUM_MIN;
        }
        if (hpExtend == null) {
            hpExtend = new HpExtend();
        }
    }

    public void setNeedChoose(boolean value) {
        this.needChoose = value;
        if (this.needChoose) {
            buffOptionId = -1;
            optionIds = null;
        }
    }

    /** 跨天重置 或 本轮一连串的挑战结束 */
    public void reset(int combatNumStart) {
        combatNumTarget = combatNumStart;
        setNeedChoose(true);
        combatCount = 0;
        hpExtend.clear();
        ing = false;
    }

    /** 本轮一连串的挑战开始 */
    public void start() {
        ing = true;
        role.sendNow(new EndlessEnterResp(ing));
    }

    /** 获取当前buff的选项ID们 */
    @JsonIgnore
    public List<Integer> getOptionIds() {
        if (optionIds == null || optionIds.isEmpty()) {
            optionIds = role.getGame().table.endless.buff.randomOptions();
        }
        return optionIds;
    }

    public void setRandomBuffId() {
        List<Integer> optList = role.getGame().table.endless.buff.randomOptions();
        if (!optList.isEmpty()) {
            this.buffOptionId = optList.get(0);
        }
    }

    /** 根据当前数据获取战斗参数 */
    @JsonIgnore
    public FightParam getFightParam(boolean chooseBuff) {
        FightParam param = new FightParam();
        boolean isOnlyOne = GDEndless.onlyOneSkills.contains(buffOptionId);
        if (buffOptionId > 0) {
            if (!isOnlyOne || chooseBuff) {
                param.sideA.buffAppend.addTeamBuff(buffOptionId);
            }
        } else {
            logger.debug("找不到buffOptionId={}, 但是可能是因为玩家下线，自动没帮他选。", buffOptionId);
        }
        param.sideA.hpExtend = this.hpExtend;
        return param;
    }
}
